﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text;
using HRProject.Code.Common;

namespace HRProject.Code.DTO
{
    public class BLShortentUser
    {
        private Guid id;

        public Guid Id
        {
            get { return id; }
            set { id = value; }
        }
        private string username;

        public string UserName
        {
            get { return username; }
            set { username = value; }
        }
        private string fullName;

        public string FullName
        {
            get { return fullName; }
            set { fullName = value; }
        }
        private string email;

        public string Email
        {
            get { return email; }
            set { email = value; }
        }

        public string InRolesToHtml
        {
            get
            {
                StringBuilder result = new StringBuilder();
                foreach (BLRole role in inRoles)
                {
                    if (!Guid.Empty.Equals(role.Id))
                    {
                        StringBuilder temp = new StringBuilder(ContentProvider.GetFormat("InRole"));
                        
                        temp.Replace("{I0}", role.Name);
                        if (!Guid.Empty.Equals(role.Department.Id))
                        {
                            temp.Replace("{I1}", role.Department.Name);
                            temp.Replace("{L0}", ContentProvider.GetValue("Role_Possess"));
                        }
                        else
                        {
                            temp.Replace("{I1}", string.Empty);
                            temp.Replace("{L0}", string.Empty);
                        }

                        StringBuilder removeButton = new StringBuilder("<div style=\"float:left;\" onmouseover=\"treeNodeMove(this);\" onmouseout=\"treeNodeOut(this);\">");
                        removeButton.Append("<div class=\"actionbar\" style=\"top:0px\">");
                        if ((Membership.GetUser() != null) && (Roles.IsUserInRole("Admin")))
                        {
                            removeButton.Append("<div class=\"item remove\" onclick=\"removeRoleFromUser(this);\"></div>");
                        }
                        removeButton.Append("<input type=\"hidden\" name=\"id\" value=\"" + Id + "\"/>");
                        removeButton.Append("<input type=\"hidden\" name=\"roleName\" value=\"" + role.Name + "\"/>");
                        removeButton.Append("</div>");
                        removeButton.Append("</div>");
                        temp.Replace("{RemoveButton}",removeButton.ToString());
                        result.Append(temp);
                    }
                }
                return result.ToString();
            }
        }

        private List<BLRole> inRoles;

        public List<BLRole> InRoles
        {
            get { return inRoles; }
            set { inRoles = value; }
        }

        public string AddButton
        {
            get
            {
                StringBuilder result = new StringBuilder("<div style=\"float:left;width:100%;height:100%\" onmouseover=\"treeNodeMove(this);\" onmouseout=\"treeNodeOut(this);\">");
                result.Append("<div class=\"actionbar\" style=\"top:0px\">");
                if ((Membership.GetUser()!=null) && (Roles.IsUserInRole("Admin")))
                {
                    result.Append("<div class=\"item add\" onclick=\"addUserToRole(this);\"></div>");
                }
                result.Append("<input type=\"hidden\" name=\"id\" value=\""+Id+"\"/>");
                result.Append("<input type=\"hidden\" name=\"name\" value=\"" + UserName + "\"/>");
                result.Append("</div>");
                result.Append("</div>");
                return result.ToString();
            }
        }
    }
}
